package parttern.factory;

public enum ShapeFactory {

    CIRCLE(new CircleShape(), "CIRCLE"), RECTANGLE(new RectangleShape(), "RECTANGLE"), SQUARE(new SquareShape(), "SQUARE");

    private final IShape shape;
    private final String name;

    ShapeFactory(IShape shape, String name) {
        this.shape = shape;
        this.name = name;
    }

    public static IShape getShape(String name) {
        for (ShapeFactory factory : ShapeFactory.values()) {
            if (factory.name.equals(name)) {
                return factory.shape;
            }
        }
        return null;
    }

    ///test
    public static void main(String[] args) {
        ShapeFactory.getShape("CIRCLE").draw();
        ShapeFactory.getShape("RECTANGLE").draw();
        ShapeFactory.getShape("SQUARE").draw();
    }
}
